<!--
 * @Author: Luxiaoxiang
 * @Date: 2022-10-11 22:42:44
 * @LastEditors: lxx
 * @LastEditTime: 2022-10-24 16:15:02
 * @Description:
 * @FilePath: \briup-ui\src\pages\admin\check\OrderComment.vue
-->
<template>
  <!-- 订单评论审核 -->
  <div>
    <!-- 第一行 -->
    <div class="header">
      <el-form :inline="true" :model="params" class="demo-form-inline">
        <el-form-item>
          <el-input
            v-model="params.content"
            placeholder="请输入评论内容"
            clearable
          />
        </el-form-item>
      
        <el-form-item>
          <el-select v-model="params.status" placeholder="请选择状态" clearable>
            <el-option label="通过" value="通过" />
            <el-option label="不通过" value="不通过" />
            <el-option label="未审核" value="未审核" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="toSearch">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <!-- 第一行结束 -->
    <!-- 第二行 -->
    <el-table :data="orderData" style="width: 100%">
      <el-table-column type="index" label="序号" />
      <el-table-column prop="content" label="评论内容" />
      <el-table-column prop="customerId" label="顾客编号" />
      <el-table-column prop="orderId" label="订单编号" />
      <el-table-column prop="commentTime" label="评论时间" />
      <el-table-column prop="status" label="评论状态">
        <template slot-scope="scope">

          <span v-if="scope.row.status === '通过'" class="onLine">通过</span>
          <span v-else-if="scope.row.status === '未审核'">未审核</span>
          <span v-else class="offLine">不通过</span>

        </template>
      </el-table-column>
      <el-table-column prop="address" label="审核">
        <template slot-scope="scope">
          <a
            v-if="scope.row.status === '通过'"
            href="#"
            class="offLine"
            @click.prevent="changeStatus(scope.row.id, '不通过')"
          >
            <el-tag type="danger">不通过</el-tag>

          </a>
          <a
            v-else
            href="#"

            @click.prevent="changeStatus(scope.row.id, '通过')"
          >
            <el-tag>通过</el-tag>
          </a>
        </template>
      </el-table-column>
      <el-table-column prop="address" label="操作">
        <template slot-scope="scope">
          <a type="text" size="small" @click.prevent="deleteComment(scope.row)">
            <el-tag type="danger"> 删除</el-tag>
          </a>
        </template>
      </el-table-column>
    </el-table>
    <!-- 第二行 表格结束 -->

    <!-- 第三行 分页按钮 -->
    <div class="bottom">
      <el-pagination
        class="page"
        :current-page="params.page"
        :page-sizes="[2, 5, 10, 20, 30]"
        :page-size="params.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>

    <!-- 第三行结束 分页按钮 -->

  </div>
</template>

<script>
import { getOrderComment, checkPass, checkNoPass } from '../../../api/orderComment'
import { get } from '@/utils/request'

export default {
  data() {
    return {
      orderData: [],
      params: {
        page: 1,
        pageSize: 10
      },
      total: 0,
    }
  },
  computed: {},
  created() {
    this.getOrderComments()
  },
  mounted() {},
  methods: {
    toSearch() {
      this.params.page = 1
      this.getOrderComments()
    },
    async  getOrderComments() {
      for (const key in this.params) {
        if (!this.params[key]) {
          delete this.params[key]
        }
      }
      const res = await getOrderComment(this.params)
      console.log(res, '获取响应')
      this.orderData = res.data.list
      this.total = res.data.total
    },
    // 页码条数发生改变的方法 默认参数pageSize
    handleSizeChange(pageSize) {
      // 当前页码发生改变的方法
      this.params.pageSize = pageSize
      this.params.page = 1
      this.getOrderComments()
    },
    // 当前页码发生改变的方法 默认参数页码page
    handleCurrentChange(page) {
      this.params.page = page
      this.getOrderComments()
    },

    changeStatus(id, status) {
      this.$confirm('此操作将改变订单评论的状态，是否继续？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async() => {
        if (status === '通过') {
          const res = await checkPass({ id })
          this.$message({
            type: 'success',
            message: res.message
          })
        } else {
          const res = await checkNoPass({ id })
          this.$message({
            type: 'success',
            message: res.message
          })
        }
        // 刷新页面
        this.getOrderComments()
      })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消我们的操作'
          })
        })
    },




    // 通过id删除
    deleteComment(row) {
      this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        get('/orderComment/deleteById', { id: row.id })
          .then(res => {
            this.$message({ type: 'success', message: res.message })
            this.getComments()
          })
      })
    }
  }
}
</script>
<style lang="scss">
$color: #30b08f;
a {
  margin-right: 10px;
}
.toEdit,
.onLine {
  color: $color;
}
.offLine {
  color: #e65d6e;
}
</style>
<style>
.bottom{
text-align: center;
margin-top: 30px;
}
</style>
